package cn.shuto.liferay.plugin.chart.service.model.impl;

import cn.shuto.liferay.plugin.chart.service.model.ChartTemplate;

import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import java.util.Date;

/**
 * The cache model class for representing ChartTemplate in entity cache.
 *
 * @author shixw
 * @see ChartTemplate
 * @generated
 */
public class ChartTemplateCacheModel implements CacheModel<ChartTemplate>,
    Externalizable {
    public String uuid;
    public long chartTemplateId;
    public long groupId;
    public long companyId;
    public long userId;
    public String userName;
    public long createDate;
    public long modifiedDate;
    public String name;
    public String description;
    public String script;
    public String templateParam;

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(25);

        sb.append("{uuid=");
        sb.append(uuid);
        sb.append(", chartTemplateId=");
        sb.append(chartTemplateId);
        sb.append(", groupId=");
        sb.append(groupId);
        sb.append(", companyId=");
        sb.append(companyId);
        sb.append(", userId=");
        sb.append(userId);
        sb.append(", userName=");
        sb.append(userName);
        sb.append(", createDate=");
        sb.append(createDate);
        sb.append(", modifiedDate=");
        sb.append(modifiedDate);
        sb.append(", name=");
        sb.append(name);
        sb.append(", description=");
        sb.append(description);
        sb.append(", script=");
        sb.append(script);
        sb.append(", templateParam=");
        sb.append(templateParam);
        sb.append("}");

        return sb.toString();
    }

    @Override
    public ChartTemplate toEntityModel() {
        ChartTemplateImpl chartTemplateImpl = new ChartTemplateImpl();

        if (uuid == null) {
            chartTemplateImpl.setUuid(StringPool.BLANK);
        } else {
            chartTemplateImpl.setUuid(uuid);
        }

        chartTemplateImpl.setChartTemplateId(chartTemplateId);
        chartTemplateImpl.setGroupId(groupId);
        chartTemplateImpl.setCompanyId(companyId);
        chartTemplateImpl.setUserId(userId);

        if (userName == null) {
            chartTemplateImpl.setUserName(StringPool.BLANK);
        } else {
            chartTemplateImpl.setUserName(userName);
        }

        if (createDate == Long.MIN_VALUE) {
            chartTemplateImpl.setCreateDate(null);
        } else {
            chartTemplateImpl.setCreateDate(new Date(createDate));
        }

        if (modifiedDate == Long.MIN_VALUE) {
            chartTemplateImpl.setModifiedDate(null);
        } else {
            chartTemplateImpl.setModifiedDate(new Date(modifiedDate));
        }

        if (name == null) {
            chartTemplateImpl.setName(StringPool.BLANK);
        } else {
            chartTemplateImpl.setName(name);
        }

        if (description == null) {
            chartTemplateImpl.setDescription(StringPool.BLANK);
        } else {
            chartTemplateImpl.setDescription(description);
        }

        if (script == null) {
            chartTemplateImpl.setScript(StringPool.BLANK);
        } else {
            chartTemplateImpl.setScript(script);
        }

        if (templateParam == null) {
            chartTemplateImpl.setTemplateParam(StringPool.BLANK);
        } else {
            chartTemplateImpl.setTemplateParam(templateParam);
        }

        chartTemplateImpl.resetOriginalValues();

        return chartTemplateImpl;
    }

    @Override
    public void readExternal(ObjectInput objectInput) throws IOException {
        uuid = objectInput.readUTF();
        chartTemplateId = objectInput.readLong();
        groupId = objectInput.readLong();
        companyId = objectInput.readLong();
        userId = objectInput.readLong();
        userName = objectInput.readUTF();
        createDate = objectInput.readLong();
        modifiedDate = objectInput.readLong();
        name = objectInput.readUTF();
        description = objectInput.readUTF();
        script = objectInput.readUTF();
        templateParam = objectInput.readUTF();
    }

    @Override
    public void writeExternal(ObjectOutput objectOutput)
        throws IOException {
        if (uuid == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(uuid);
        }

        objectOutput.writeLong(chartTemplateId);
        objectOutput.writeLong(groupId);
        objectOutput.writeLong(companyId);
        objectOutput.writeLong(userId);

        if (userName == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(userName);
        }

        objectOutput.writeLong(createDate);
        objectOutput.writeLong(modifiedDate);

        if (name == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(name);
        }

        if (description == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(description);
        }

        if (script == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(script);
        }

        if (templateParam == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(templateParam);
        }
    }
}
